# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.loader import ItemLoader
from scrapy.loader.processors import MapCompose, TakeFirst


class HouseItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass


class zufang_lianjiaItemLoader(ItemLoader):
    default_output_processor = TakeFirst()


class zufang_lianjiaItem(scrapy.Item):
    id = scrapy.Field()
    title = scrapy.Field()
    price = scrapy.Field()
    fitment = scrapy.Field()
    # base
    squire = scrapy.Field()
    room_status = scrapy.Field()
    floor = scrapy.Field()
    face_to = scrapy.Field()
    subway = scrapy.Field()
    # details
    rant_way = scrapy.Field()
    pay_way = scrapy.Field()
    now_status = scrapy.Field()
    hot_way = scrapy.Field()
    # long user description
    long_description = scrapy.Field()
    tag = scrapy.Field()
    # time
    visit_in_seven = scrapy.Field()
    visit_in_thirty = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            INSERT INTO zufang_lianjia(
            id,title,price,fitment,squire,room_status,floor,face_to,subway,rant_way,pay_way,now_status,hot_way,long_description,tag,visit_in_seven,visit_in_thirty
            )VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
            ON DUPLICATE KEY UPDATE
            id = VALUES (id),
            title = VALUES (title),
            price = VALUES (price),
            fitment = VALUES (fitment),
            squire = VALUES (squire),
            room_status = VALUES (room_status),
            floor = VALUES (floor),
            face_to = VALUES (face_to),
            subway = VALUES (subway),
            rant_way = VALUES (rant_way),
            pay_way = VALUES (pay_way),
            now_status = VALUES (now_status),
            hot_way = VALUES (hot_way),
            long_description = VALUES (long_description),
            tag = VALUES (tag),
            visit_in_seven = VALUES (visit_in_seven),
            visit_in_thirty = VALUES (visit_in_thirty)
        """
        params = (
            self['id'],
            self['title'],
            self['price'],
            self['fitment'],
            self['squire'],
            self['room_status'],
            self['floor'],
            self['face_to'],
            self['subway'],
            self['rant_way'],
            self['pay_way'],
            self['now_status'],
            self['hot_way'],
            self['long_description'],
            self['tag'],
            self['visit_in_seven'],
            self['visit_in_thirty'],
        )
        return insert_sql, params


def set_default(num):
    if num:
        return num
    else:
        return "null"


class ershou_lianjiaItemLoader(ItemLoader):
    default_input_processor = MapCompose(set_default)
    default_output_processor = TakeFirst()


class ershou_lianjiaItem(scrapy.Item):
    # string = "id,title,price,unit_price,tax_pay,room1,room2,type1,type2,area1,area2,community_name,community_area,long_detail,tag,visit_in_seven,visit_in_thirty"
    # string2 = "detail0,detail1,detail2,detail3,detail4,detail5,detail6,detail7,detail8,detail9,detail10,detail11,detail12,detail13,detail14,detail15,detail16,detail17,detail18,detail19,"
    id = scrapy.Field()
    title = scrapy.Field()
    price = scrapy.Field()
    unit_price = scrapy.Field()
    tax_pay = scrapy.Field()
    room1 = scrapy.Field()
    room2 = scrapy.Field()
    type1 = scrapy.Field()
    type2 = scrapy.Field()
    area1 = scrapy.Field()
    area2 = scrapy.Field()
    community_name = scrapy.Field()
    community_area = scrapy.Field()
    long_detail = scrapy.Field()
    tag = scrapy.Field()
    visit_in_seven = scrapy.Field()
    visit_in_thirty = scrapy.Field()
    detail0 = scrapy.Field()
    detail1 = scrapy.Field()
    detail2 = scrapy.Field()
    detail3 = scrapy.Field()
    detail4 = scrapy.Field()
    detail5 = scrapy.Field()
    detail6 = scrapy.Field()
    detail7 = scrapy.Field()
    detail8 = scrapy.Field()
    detail9 = scrapy.Field()
    detail10 = scrapy.Field()
    detail11 = scrapy.Field()
    detail12 = scrapy.Field()
    detail13 = scrapy.Field()
    detail14 = scrapy.Field()
    detail15 = scrapy.Field()
    detail16 = scrapy.Field()
    detail17 = scrapy.Field()
    detail18 = scrapy.Field()
    detail19 = scrapy.Field()

    # 37

    def get_insert_sql(self):
        insert_sql = """
            INSERT INTO ershou_lianjia(
            id,title,price,unit_price,tax_pay,room1,room2,type1,type2,area1,area2,community_name,community_area,long_detail,tag,visit_in_seven,visit_in_thirty,detail0,detail1,detail2,detail3,detail4,detail5,detail6,detail7,detail8,detail9,detail10,detail11,detail12,detail13,detail14,detail15,detail16,detail17,detail18,detail19
            )VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
            ON DUPLICATE KEY UPDATE
            id = VALUES(id),
            title = VALUES(title),
            price = VALUES(price),
            unit_price = VALUES(unit_price),
            tax_pay = VALUES(tax_pay),
            room1 = VALUES(room1),
            room2 = VALUES(room2),
            type1 = VALUES(type1),
            type2 = VALUES(type2),
            area1 = VALUES(area1),
            area2 = VALUES(area2),
            community_name = VALUES(community_name),
            community_area = VALUES(community_area),
            long_detail = VALUES(long_detail),
            tag = VALUES(tag),
            visit_in_seven = VALUES(visit_in_seven),
            visit_in_thirty = VALUES(visit_in_thirty),
            detail0 = VALUES(detail0),
            detail1 = VALUES(detail1),
            detail2 = VALUES(detail2),
            detail3 = VALUES(detail3),
            detail4 = VALUES(detail4),
            detail5 = VALUES(detail5),
            detail6 = VALUES(detail6),
            detail7 = VALUES(detail7),
            detail8 = VALUES(detail8),
            detail9 = VALUES(detail9),
            detail10 = VALUES(detail10),
            detail11 = VALUES(detail11),
            detail12 = VALUES(detail12),
            detail13 = VALUES(detail13),
            detail14 = VALUES(detail14),
            detail15 = VALUES(detail15),
            detail16 = VALUES(detail16),
            detail17 = VALUES(detail17),
            detail18 = VALUES(detail18),
            detail19 = VALUES(detail19)
            """
        params = (
            self['id'],
            self['title'],
            self['price'],
            self['unit_price'],
            self['tax_pay'],
            self['room1'],
            self['room2'],
            self['type1'],
            self['type2'],
            self['area1'],
            self['area2'],
            self['community_name'],
            self['community_area'],
            self['long_detail'],
            self['tag'],
            self['visit_in_seven'],
            self['visit_in_thirty'],
            self['detail0'],
            self['detail1'],
            self['detail2'],
            self['detail3'],
            self['detail4'],
            self['detail5'],
            self['detail6'],
            self['detail7'],
            self['detail8'],
            self['detail9'],
            self['detail10'],
            self['detail11'],
            self['detail12'],
            self['detail13'],
            self['detail14'],
            self['detail15'],
            self['detail16'],
            self['detail17'],
            self['detail18'],
            self['detail19'],
        )
        return insert_sql, params
